package com.hrt.manage.product.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.hrt.base.BaseDaoImpl;
import com.hrt.bean.GiftDetail;
import com.hrt.bean.GiftInfor;
import com.hrt.manage.product.dao.GiftInforDao;

@Repository
public class GiftInforDaoImpl extends BaseDaoImpl<GiftInfor> implements GiftInforDao{

	@SuppressWarnings("unchecked")
	@Override
	public List<GiftInfor> findDelAll() {
		
		return getHibernateTemplate().find("FROM GiftInfor WHERE isDelete=0");
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<GiftInfor> queryGiftInfors(String itemCondition) {
		
			String hql="select gift from GiftInfor gift where gift.isdelete=0 and (gift.giftCode like '%"+itemCondition+"%'"+" or gift.giftName like '%"+itemCondition+"%'"+")";
			
			List<GiftInfor> results=new ArrayList<GiftInfor>();
			
			 results= getHibernateTemplate().find(hql);
			return results;
		
	}
	/**
	 * 根据礼品id查询礼品规格
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<GiftDetail> getGiftDetailByGiftId(Long giftId) {
		String hql = "select detail from GiftDetail detail where detail.isdelete=0 and detail.giftId='"+giftId+"' and detail.ispush=1";
		return getHibernateTemplate().find(hql);
	}
	
	/**
	 * 根据礼品ID 加载所有礼品规格（不分上下架）
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<GiftDetail> getGiftDetailsByGiftId(Long giftId) {
		String hql = "select detail from GiftDetail detail where detail.isdelete=0 and detail.giftId='"+giftId+"'";
		return getHibernateTemplate().find(hql);
	}

}
